package com.personal.test.controller.importExcel;

import com.fasterxml.jackson.databind.exc.InvalidFormatException;
import com.personal.test.common.domin.R;
import com.personal.test.service.ImportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.text.ParseException;

/**
 * @author linyh
 * @version 1.0
 * @email 1503386669@qq.com
 * @date 2020/10/20 17:19
 */
@Controller
public class ImportController {

    @Autowired
    private ImportService importService;
    /**
     * Excel文件数据导入到数据库
     * @return
     */
    @PostMapping("/import")
    @ResponseBody
    public R importExcel(@RequestParam(value="file",required = false) MultipartFile file) throws IOException, ParseException, InvalidFormatException {
        return importService.readExcelFile(file);
    }
}
